package com.partner.share.work.mq.consumer;

import com.partner.share.work.mq.construction.ActiveMQQueueConst;
import com.partner.share.work.websocket.WebSocketUtil;
import com.partner.share.work.websocket.server.WebsocketService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;
import org.springframework.jms.annotation.JmsListener;
import org.springframework.stereotype.Component;

/**
 * @author pengyangyan
 * @version 1.0.0
 * @date 2019年09月29日 09:50:00
 */
//@Component
//@Order(1)
public class ActiveMQQueueConsumer {

    @Autowired
    WebsocketService websocketService;

    private final static Logger logger = LoggerFactory.getLogger(ActiveMQQueueConsumer.class);

    /**
     * WebSocket的Java老司机聊天室队列消息消费者
     */
    @JmsListener(destination = ActiveMQQueueConst.QUEUE_NAME_WEBSOCKET_CHATROOM_ONE, containerFactory = ActiveMQQueueConst.BEAN_NAME_JMSLISTENERCONTAINERFACTORY)
    public void receiveQueueWebSocketJavalsjChatroomMsg(String message) {
        logger.info("消费了一条主题[{}]消息{}。", ActiveMQQueueConst.QUEUE_NAME_WEBSOCKET_CHATROOM_ONE, message);
        websocketService.broadcast(message);
    }

}
